package cn.doctor.assistant.pad.ui.hudong;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import butterknife.ButterKnife;
import butterknife.InjectView;
import cn.doctor.assistant.pad.MyApplication;
import cn.doctor.assistant.pad.R;
import cn.doctor.assistant.pad.base.BaseFragment;
import cn.doctor.assistant.pad.entity.ContactInfo;

/**
 * Created by jiaolf on 2016/3/21.
 * 互动
 */
public class IMFragment extends BaseFragment implements IContantSelectedListener{

    FragmentManager fm;
    ContactsFragment contactsFragment;

    @InjectView(R.id.chat_user_info_title)
    TextView chatUserInfoTitle;
    @InjectView(R.id.chat_user_info_gender)
    TextView chatUserInfoGender;
    @InjectView(R.id.chat_user_info_phone)
    TextView chatUserInfoPhone;

    private View rootView;

    public static IMFragment newInstance() {
        return new IMFragment();
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);
        rootView = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_hudong, container, false);
        ButterKnife.inject(this, rootView);
        MyApplication.getInstance().addContactSelectedListener(this);
        return rootView;
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        fm = getActivity().getSupportFragmentManager();
        contactsFragment = (ContactsFragment)(fm.findFragmentById(R.id.f_hudong_contacts));
    }

    @Override
    public void onRedisplay() {
        super.onRedisplay();
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.reset(this);
        MyApplication.getInstance().removeContactSelectedListener(this);
    }

    @Override
    public void onSelected(ContactInfo user) {
        chatUserInfoTitle.setText(user.getName() + "个人资料");
        chatUserInfoPhone.setText("手机号:" + user.getPhone());
        chatUserInfoGender.setText("性别："+ user.getGender());
    }
}
